<html>
<title>Room Chooser</title>
<head>
    <link rel="stylesheet" type="text/css" href="../css/styles.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/funcs.js"></script>
    <link rel="icon" type="image/png" href="../images/favicon.png">
    
</head>
<body>
    <article>
        <div class="heading"><h3>Welcome to the Room Chooser!</h3></div>
        <table class="noborder">
            <tr>
                <td class="noborder"><?php require("room_table.php");?></td>
            <td class="noborder"><div class="chooser center">
                    <form name="myForm" method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>">
                            <select onchange="document.myForm.submit();" name="building" placeholder="Buildings">
                                <option value="">Building</option>
                            <?php
                                $b = $_GET['building'];
                                require('/connect.php');
                                $query="SELECT *
                                    FROM buildings";
                                $result=mysqli_query($con, $query);
                            while($row = mysqli_fetch_assoc($result)){
                                $BN = $row['Building_Name'];
                                $BID = $row['BID'];
                                echo "<option value='$BID'"; 
                                if($b===$BID){
                                    echo "selected=\"selected\"";
                                }
                                    echo ">$BN</option> ";
                            }    
                            mysqli_close($con);
                            ?>
                            </select>
               <select onchange="document.myForm.submit();" name="floor_number" placeholder="Floors">
                    <option value="0">Floor</option>
                    <?php
                        $f = $_GET['floor_number'];
                        require('/connect.php');
                        $query1="SELECT Floors
                            FROM Buildings
                            WHERE BID=$b";

                    $result1=mysqli_query($con, $query1);
                    $row1=mysqli_fetch_assoc($result1);
                    for($i=1;$i<=$row1['Floors'];$i++){
                        echo "<option value='$i'";
                        if($i==$f){
                            echo "selected=\"selected\"";
                        }
                        echo ">$i</option>";
                    }
                    mysqli_close($con);
                    ?>
                    </select>
                <select onchange="document.myForm.submit()" name="room_number" placeholder="Rooms">
                    <option value="0" >Room</option>
                    <?php
                        require('/connect.php');
                        $query2="SELECT *
                            FROM rooms
                            WHERE floor=$f AND BID=$b;";
                    $result2=mysqli_query($con, $query2);
                    while ($row2 = mysqli_fetch_assoc($result2)) {
                        $rid =$row2['room_number'];
                        //$roomNum = $_GET[room_number];
                        echo "<option value=$rid";
                        if($rid === $_GET[room_number]){
                            echo "selected=\"selected\"";
                        }
                        echo ">$rid</option>";
                }
                    mysqli_close($con);
                    ?>
                    </select>
                    </form>

                    <?php if(isset($_GET['room_number']))
                    {echo"
                    <a href=\"#\" onclick='addRoom(".$b.$_GET['room_number']."); '>
                        <img src=\"../images/submit.png\"></a>";}    
                    ?>
                </div></td>
                <td class="noborder floorplan" colspan=2><img src="../images/<?php require('/connect.php');
                        $query4="SELECT Building_Name
                            FROM buildings
                            WHERE BID=$b";
                        $result4=mysqli_query($con, $query4);
                        $row=  mysqli_fetch_assoc($result4);
                        $BNT=$row['Building_Name'];
                    mysqli_close($con);
                    echo"$BNT $f";?>.png" alt="Floorplan" width="300"></td>
            </tr>
                <tr><td colspan=4 class="noborder center"><input class="button" type="button" onclick="window.location.href='../index.php';"  value="Go Back" /></td></tr>
        </table>
    </article>
    <footer>
        <p>Posted by: Team Vollun</p>
        <p><time pubdate datetime="2013-04-03"></time></p>
    </footer>
</body>
</html>


